use log::debug;

pub async fn post_request<T>(url: T, json_data: serde_json::Value) -> Result<String, reqwest::Error>
where
    T: AsRef<str> + reqwest::IntoUrl,
{
    let client = reqwest::Client::new();
    let response = client
        .post(url) // 替换为你要请求的 URL
        .header(reqwest::header::CONTENT_TYPE, "application/json") // 设置请求头
        .body(json_data.to_string()) // 设置请求体
        .send()
        .await?;
    let response_text = response.text().await?;
    debug!("Post Response:{:?}", &response_text);
    Ok(response_text)
}
pub async fn download_image<T>(url: T) -> Result<Vec<u8>, reqwest::Error>
where
    T: AsRef<str> + reqwest::IntoUrl,
{
    let client = reqwest::Client::new();
    let response = client.get(url).send().await?;
    let bytes = response.bytes().await?;
    Ok(bytes.to_vec())
}
